﻿#include "FieldNameTranslate.h"

FieldnameTranslate* FieldnameTranslate::instance()
{
	//没必要new  没有初始化的东西：直接用静态的就行
	static FieldnameTranslate fieldtranslate;
	return &fieldtranslate;
}

void FieldnameTranslate::addTranslate(const QString& field, const QString& translate)
{
	auto isExists = m_map.find(field);
	if ( isExists != m_map.end())
	{
		qWarning() << "field > " << field << "is exists";
	}

	//插入键值对：
	m_map.insert(field, translate);
}

QString FieldnameTranslate::translate(const QString& field)
{
	return translate("",field);
}

QString FieldnameTranslate::translate(const QString& group, const QString& field)
{
	QString result;
	if (group.isEmpty())
	{
		result = field;
	}
	else
	{
		result = group + "/" + field;
	}

	auto findData = m_map.find(result);
	if (findData == m_map.end())
	{
		qWarning() << result << "is not exists";
		return field;
	}

	return m_map.value(result);
}
